<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE HTML>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <base href="<%=basePath%>">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Home</title>
	
	<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
	<link rel="stylesheet" href="assets/materialize/css/materialize.min.css" media="screen,projection" />
    <!-- Bootstrap Styles-->
    <link href="assets/css/bootstrap.css" rel="stylesheet" />
    <!-- FontAwesome Styles-->
    <link href="assets/css/font-awesome.css" rel="stylesheet" />
    <!-- Morris Chart Styles-->
    <link href="assets/js/morris/morris-0.4.3.min.css" rel="stylesheet" />
    <!-- Custom Styles-->
    <link href="assets/css/custom-styles.css" rel="stylesheet" />
    <!-- Google Fonts-->
    <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
    <script type="application/javascript" src="layui/dist/layui.all.js"></script>
    <link rel="stylesheet" type="text/css" href="layui/dist/css/layui.css">
    <link rel="stylesheet" href="assets/js/Lightweight-Chart/cssCharts.css">
    <script src="js/jq.js"></script>
    <script src="js/jquery.form.min.js"></script>
    <style>
        iframe{
            display: none;
        }
    </style>
</head>
<body>
    <div id="wrapper">
        <nav class="navbar navbar-default top-navbar" role="navigation">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle waves-effect waves-dark" data-toggle="collapse" data-target=".sidebar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand waves-effect waves-dark" href="back.jsp"><i class="large material-icons">insert_chart</i> <strong>干饭魂</strong></a>
				
		<div id="sideNav" href=""><i class="material-icons dp48">toc</i></div>
            </div>


        </nav>
		<!-- Dropdown Structure -->

	   <!--/. NAV TOP  -->
        <nav class="navbar-default navbar-side" role="navigation">
            <div class="sidebar-collapse">
                <ul class="nav" id="main-menu">

                    <li>
                        <a class="active-menu waves-effect waves-dark" href="back.jsp"><i class="fa fa-dashboard"></i>首页</a>
                    </li>




                </ul>

            </div>

        </nav>
        <!-- /. NAV SIDE  -->
      
		<div id="page-wrapper">
		  <div class="header">
                        <h1 class="page-header">
                            数据统计
                        </h1>


		</div>
            <div id="page-inner">


                <div class="row" id="baseinfo">

                    <div class="col-xs-12 col-sm-6 col-md-3">

                        <div class="card horizontal cardIcon waves-effect waves-dark">
                            <div class="card-image blue">
                                <i class="fa fa-comments fa-5x"></i>
                            </div>
                            <div class="card-stacked">
                                <div class="card-content">
                                    <h3></h3>
                                </div>
                                <div class="card-action">
                                    <strong>订单数量</strong>
                                </div>
                            </div>
                        </div>

                    </div>

                    <div class="col-xs-12 col-sm-6 col-md-3">

						<div class="card horizontal cardIcon waves-effect waves-dark">
						<div class="card-image orange">
						<i class="fa fa-shopping-cart fa-5x"></i>
						</div>
						<div class="card-stacked">
						<div class="card-content">
						<h3></h3>
						</div>
						<div class="card-action">
						<strong>商铺数量</strong>
						</div>
						</div>
						</div>
                    </div>

                    <div class="col-xs-12 col-sm-6 col-md-3">

					<div class="card horizontal cardIcon waves-effect waves-dark">
						<div class="card-image">
						<i class="fa fa-users fa-5x"></i>
						</div>
						<div class="card-stacked">
						<div class="card-content">
						<h3></h3>
						</div>
						<div class="card-action">
						<strong>注册用户数量</strong>
						</div>
						</div>
						</div>

                    </div>
                </div>


                <br>
                <br>

                <form id="shopform"  onsubmit="return false;" action="regshop" method="post"  enctype="multipart/form-data">
                    <h1>商铺注册</h1>
                    <br>
                    <div class="form-group">
                        <h4>店铺名</h4>

                        <input name="shop_name" type="text" class="form-control" id="exampleInputEmail1" placeholder="请输入要注册的店铺名">

                    </div>
                    <div class="form-group">
                        <h4>店铺地址</h4>
                        <input name="shop_address" type="text" class="form-control" id="exampleInputPassword1" placeholder="请输入你注册的店铺地址">

                    </div>
                    <div class="form-group">
                        <h4>店铺简介</h4>
                        <input  name="shop_value" type="text" class="form-control" id="exampleInputadress" placeholder="简介">
                    </div>
                    <div class="form-group">
                        <label for="inputfile"  style="font-size: 20px">上传图片</label>
                        <input type="file" id="inputfile" name="img">
                        <label style="font-size: 15px;padding-left: 100px">图片阅览</label>
                        <div id="imagg" style="height: 100px;width: 50px;margin-left: 100px;"></div>
                    </div>

                    <button type="submit" class="btn btn-default">注册</button>
                </form>
                <br>
                <br>



                <form id="menuform"  onsubmit="return false;" action="regmenu" method="post"  enctype="multipart/form-data">
                    <h1>菜品添加</h1>
                    <br>

                    <div class="form-group">
                        <h4>要添加菜品的店铺名</h4>

                        <input name="shop_menu_name" type="text" class="form-control"  placeholder="请输入店铺名">

                    </div>
                    <div class="form-group">
                        <h4>菜名</h4>

                        <input name="menu_name" type="text" class="form-control"  placeholder="请输入菜名">

                    </div>
                    <div class="form-group">
                        <h4>菜品价格</h4>
                        <input name="price" type="text" class="form-control" placeholder="请输入菜的价格">

                    </div>
                    <div class="form-group">
                        <label for="menufile"  style="font-size: 20px">上传图片</label>
                        <input  id="menufile" type="file"  name="img">
                        <label  style="font-size: 15px;padding-left: 100px">图片阅览</label>
                        <div id="menuimg" style="height: 100px;width: 50px;margin-left: 100px;"></div>
                    </div>

                    <button type="submit" class="btn btn-default">注册</button>
                </form>











            </div>
            <!-- /. PAGE INNER  -->
        </div>
        <!-- /. PAGE WRAPPER  -->
    </div>
    <!-- /. WRAPPER  -->
    <!-- JS Scripts-->
    <!-- jQuery Js -->

	
	<!-- Bootstrap Js -->
    <script src="assets/js/bootstrap.min.js"></script>
	
	<script src="assets/materialize/js/materialize.min.js"></script>
	
    <!-- Metis Menu Js -->
    <script src="assets/js/jquery.metisMenu.js"></script>
    <!-- Morris Chart Js -->
    <script src="assets/js/morris/raphael-2.1.0.min.js"></script>
    <script src="assets/js/morris/morris.js"></script>
	
	
	<script src="assets/js/easypiechart.js"></script>
	<script src="assets/js/easypiechart-data.js"></script>
	
	 <script src="assets/js/Lightweight-Chart/jquery.chart.js"></script>
	
    <!-- Custom Js -->
    <script src="assets/js/custom-scripts.js"></script> 
 

<script>
    var layer
        ,form ;


    (  function (){
        layer=layui.layer;
        form=layui.form;
        var shopnameflag=false;
        var shopnamemenu=false;

        $.ajax({
            type: "POST",
            url: '<%=path%>/backbaseinfo',
            dataType:'json',
            success: function (result) {

                    $("#baseinfo>div:eq(0)").find("h3").text(result.data.ordercount)
                $("#baseinfo>div:eq(1)").find("h3").text(result.data.shopcount)
                $("#baseinfo>div:eq(2)").find("h3").text(result.data.usercount)


            },
            error: function(data) {

            }

        });



        var imgg = new Image();
        imgg.height=100;
        imgg.width=100;
        imgg.src="images/shop/默认店铺.jpg"
        $("#imagg").get(0).appendChild(imgg);



        $("#inputfile").on("change",function () {
            var file;
            var destination = $("#imagg").get(0)
            destination.innerHTML = '';
            file = this.files[0];
            if(file.type.indexOf('image') != -1) {
                var reader = new FileReader();
                reader.readAsDataURL(file);
                reader.onload = function(e) {
                    var img = new Image();
                    img.width=100;
                    img.height=100;
                    img.src = e.target.result;
                    destination.appendChild(img);
                };
            }

        });


        var imgg = new Image();
        imgg.height=100;
        imgg.width=100;
        imgg.src="images/shop/默认店铺.jpg"
        $("#menuimg").get(0).appendChild(imgg);



        $("#menufile").on("change",function () {
            var file;
            var destination = $("#menuimg").get(0)
            destination.innerHTML = '';
            file = this.files[0];
            if(file.type.indexOf('image') != -1) {
                var reader = new FileReader();
                reader.readAsDataURL(file);
                reader.onload = function(e) {
                    var img = new Image();
                    img.width=100;
                    img.height=100;
                    img.src = e.target.result;
                    destination.appendChild(img);
                };
            }

        });


        $("input[name=shop_menu_name]").on("blur",function () {
            if ($("input[name=shop_menu_name]").val()!=""){
                $.ajax({
                    type: "GET",
                    url: '<%=path%>/checkshopname',
                    dataType:'json',
                    data: {shopname:$("input[name=shop_menu_name]").val()},
                    success: function (result) {


                        layer.msg("没有查询到对应店铺请重新输入",{
                            icon:2,
                            time:2000
                        })
                        shopnamemenu=false;
                        $("input[name=shop_menu_name]").val("")
                    },
                    error: function(data) {

                        layer.msg("找到对应店铺可以继续添加菜品",{
                            icon:1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        })
                        shopnamemenu=true;
                    }

                });

            }

        })


        $("#menuform").submit(function () {
            if (shopnamemenu==true){


                $("#menuform").ajaxSubmit({

                    success: function(data) {
                        layer.msg("菜品创建成功",{
                            icon:1,
                            time:2000
                        })
                        $("#menuform").resetForm();//成功后重置表单
                    },
                    error:function () {
                        layer.msg("没有找到对应的店铺",{
                            icon:2,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        })
                        $("#menuform").resetForm();//失败后也重置表单
                    }


                });

            }else{
                layer.msg("没有找到对应的店铺",{
                    icon:2,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                })
            }
            return false; // 必须返回false，否则表单会自己再做一次提交操作，并且页面跳转
        })




        $("input[name=shop_name]").on("blur",function () {
            if ($("input[name=shop_name]").val()!=""){
                $.ajax({
                    type: "GET",
                    url: '<%=path%>/checkshopname',
                    dataType:'json',
                    data: {shopname:$("input[name=shop_name]").val()},
                    success: function (result) {

                        shopnameflag=true;
                        layer.msg("店铺名没有重复可以使用",{
                            icon:1,
                            time:2000
                        })

                    },
                    error: function(data) {
                        shopnameflag=false;
                        layer.msg("店铺重名,请重新填写店铺名",{
                            icon:2,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        })
                        $("input[name=shop_name]").val("")
                    }

                });

            }


        })
        $("#shopform").submit(function () {
            if (shopnameflag==true){


                $("#shopform").ajaxSubmit({

                    success: function(data) {
                        layer.msg("店铺创建成功",{
                            icon:1,
                            time:2000
                        })
                        $("#shopform").resetForm();//成功后重置表单
                        shopnameflag==false
                    },
                    error:function () {
                        layer.msg("店铺重名,店铺创建失败",{
                            icon:2,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        })
                        $("#shopform").resetForm();//失败后也重置表单
                    }


                });

            }else{
                layer.msg("店铺重名,请重新填写店铺名",{
                    icon:2,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                })
            }
        return false; // 必须返回false，否则表单会自己再做一次提交操作，并且页面跳转
        }

        )


    })();




</script>
</body>

</html>